package core.entities;

import java.util.Random;

/**
 * Location enumeration<BR />
 * This enumeration defines the possible
 * locations for a card during a game.
 * @author Y. Bondue
 * @version 1.0.0
 *
 */
public enum Location {
	
	UNKNOWN(-1, "Inconnu"),
	WEST(0, "Gauche"),
	NORTH(1, "Haut"),
	EAST(2, "Droite"),
	SOUTH(3, "Bas");
	
	private final int location;
	private final String name;
	
	Location(int location, String name) {
		this.location = location;
		this.name = name;
	}
	
	public int getLocation() {
		return location;
	}
	
	@Override
	public String toString() {
		return name;
	}
	
	public static Location getRandomLocation() {
		Location[] properValues = properValues();
		return properValues[new Random().nextInt(properValues.length)];
	}
	
	public static Location[] properValues() {
		Location[] values = values();
		Location[] properValues = new Location[values.length-1];
		int j = 0;
		for (int i = 0; i < values.length; i++) {
			if (values[i] != UNKNOWN) {
				properValues[j++] = values[i];
			}
		}
		return properValues;
	}
	
	public static Location getLocationFromInteger(int location) {
		switch (location) {
		case 0:
			return WEST;
		case 1:
			return NORTH;
		case 2:
			return EAST;
		case 3:
			return SOUTH;
		default :
			return UNKNOWN;
		}
	}
}
